import request from '@/api/request'
import g from "@/utils/utilFn";

export function users_getlist(param) {
    param = g.objEngraving({
        account: "",
        state: "",
        is_admin: "",
        page: 1,
        limit: 20,
        filed: 'id',
        sort: 'ascending'
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/users/getlist',
        method: 'POST',
        data
    })
}

export function reset_pwd(param) {
    param = g.objEngraving({
        id: "0",
        old_password: "",
        password: ""
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/users/reset_pwd',
        method: 'POST',
        data
    })
}
export function init_pwd(param) {
    param = g.objEngraving({
        id: "0",
        password: ""
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/users/init_pwd',
        method: 'POST',
        data
    })
}

export function remove_by_id(id) {
    let data = new FormData()
    data.append("id", id || "");
    return request({
        url: '/users/remove_by_id',
        method: 'POST',
        data
    })
}
export function recovery(id) {
    let data = new FormData()
    data.append("id", id || "");
    return request({
        url: '/users/recovery',
        method: 'POST',
        data
    })
}
export function add(param) {
    param = g.objEngraving({
        account: "",
        password: ""
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/users/add',
        method: 'POST',
        data
    })
}

export function getModuleIdByUser(param) {
    param = g.objEngraving({
        user_id: "0",
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/users/getModuleIdByUser',
        method: 'POST',
        data
    })
}




export function bindModule(param) {
    param = g.objEngraving({
        user_id: "0",
        module_ids: ""
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/users/bindModule',
        method: 'POST',
        data
    })
}


export function existAccount(param) {
    param = g.objEngraving({
        account: ""
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/users/existAccount',
        method: 'POST',
        data
    })
}
export function getRoleIdByUser(param) {
    param = g.objEngraving({
        user_id: "0",
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/users/getRoleIdByUser',
        method: 'POST',
        data
    })
}

export function bindRoles(param) {
    param = g.objEngraving({
        user_id: "0",
        role_ids: ""
    }, param || {})
    let data = new FormData()
    Object.keys(param).map((key) => {
        data.append(key, param[key] || "");
    });
    return request({
        url: '/users/bindRoles',
        method: 'POST',
        data
    })
}

export const stateOptions = [
    { key: '0', name: '未登录' },
    { key: '1', name: '已登录' },
    { key: '2', name: '冻结' },
    { key: '3', name: '注销' },
    { key: '4', name: '不可用' },
    { key: '5', name: '已删除' }
]

export const isAdminOptions = [
    { key: '3', name: '普通用户' },
    { key: '1', name: '超级用户' },
    { key: '2', name: '编辑者' }
]